<template>
  <page-header-wrapper>
    <page-tab-list>
      <a-alert message="此配置用于登录隐私政策/服务协议下载" type="info" show-icon style="margin: 24px 0" />
      <a-form-model ref="appForm" :model="appSetting" :labelCol="{ span: 3 }" :wrapperCol="{ span: 7 }">
        <a-form-model-item label="客户端隐私政策" prop="client_privacy_id" help="关联营销->文章下边的内容">
          <a-select style="width: 300px" v-model="appSetting.client_privacy_id">
            <a-select-option v-for="(item, index) in articleList" :key="index" :title="item.name" :value="item.id">
              {{ item.name }}
            </a-select-option>
          </a-select>
        </a-form-model-item>
        <a-form-model-item label="客户端服务协议" prop="client_service_id" help="关联营销->文章下边的内容">
          <a-select style="width: 300px" v-model="appSetting.client_service_id">
            <a-select-option v-for="(item, index) in articleList" :key="index" :title="item.name" :value="item.id">
              {{ item.name }}
            </a-select-option>
          </a-select>
        </a-form-model-item>
        <a-form-model-item label="APP下载地址（Android）" prop="app_down_android">
          <a-input v-model="appSetting.app_down_android" />
        </a-form-model-item>
        <a-form-model-item label="APP下载地址（IOS）" prop="app_down_ios">
          <a-input v-model="appSetting.app_down_ios" />
        </a-form-model-item>
        <a-form-model-item :wrapper-col="{ span: 7, offset: 2 }">
          <a-button :loading="btnLoading" type="primary" @click="submitForm"> 保存 </a-button>
        </a-form-model-item>
      </a-form-model>
    </page-tab-list>
  </page-header-wrapper>
</template>
<script>
import { settingApp, getAppSetting } from '@/api/store'
import { getAboutArticle } from '@/api/content'

export default {
  name: 'SettingApp',
  data() {
    return {
      loading: false,
      appSetting: {
        app_down_android: '',
        app_down_ios: '',
        client_privacy_id: '',
        client_service_id: '',
      },
      articleList: [],
      btnLoading: false,
    }
  },
  created() {
    this.getData()
    this.article()
  },
  methods: {
    article() {
      return getAboutArticle({ is_have_page: 0 }).then((res) => {
        if (res.code == 0) {
          this.articleList = res.data
        }
      })
    },
    getData: function () {
      this.loading = true
      getAppSetting({})
        .then((res) => {
          if (res.code == 0) {
            this.appSetting.app_down_android = res.data.app_down_android
            this.appSetting.app_down_ios = res.data.app_down_ios
            this.appSetting.client_privacy_id = res.data.client_privacy_id
            this.appSetting.client_service_id = res.data.client_service_id
          }
        })
        .catch((error) => {
          console.log(error)
        })
        .then(() => {
          this.loading = false
        })
    },
    submitForm: function () {
      this.btnLoading = true
      settingApp({
        app_down_android: this.appSetting.app_down_android,
        app_down_ios: this.appSetting.app_down_ios,
        client_privacy_id: this.appSetting.client_privacy_id,
        client_service_id: this.appSetting.client_service_id,
      })
        .then((res) => {
          if (res.code == 0) {
            this.$message.success(res.msg)
          } else {
            this.$message.warning(res.msg)
          }
        })
        .catch((error) => {
          console.log(error)
        })
        .then(() => {
          this.btnLoading = false
        })
    },
  },
}
</script>
<style scoped>
</style>
